package cn.wang.spring;

import cn.wang.spring.Paper;

public class TextPaper implements Paper {
    private Ink ink=null;

    public Ink getInk() {
        return ink;
    }

    public void setInk(Ink ink) {
        this.ink = ink;
    }

    public Paper getPaper() {
        return paper;
    }

    public void setPaper(Paper paper) {
        this.paper = paper;
    }

    public int getCharPerLine() {
        return charPerLine;
    }

    public int getLinePerLine() {
        return linePerLine;
    }

    public void setContent(String content) {
        this.content = content;
    }

    public int getPosX() {
        return posX;
    }

    public void setPosX(int posX) {
        this.posX = posX;
    }

    public int getPosY() {
        return posY;
    }

    public void setPosY(int posY) {
        this.posY = posY;
    }

    public int getPosP() {
        return posP;
    }

    public void setPosP(int posP) {
        this.posP = posP;
    }

    public String getLinePerPage() {
        return linePerPage;
    }

    public void setLinePerPage(String linePerPage) {
        this.linePerPage = linePerPage;
    }

    private Paper paper =null;
    private int charPerLine = 16;
    private int linePerLine = 5;
    private String content ="";
    private int posX = 0;
    private int posY = 0;
    private int posP = 1;
    private String linePerPage;

    @Override
    public void putInChar(char c) {
        content +=c;
        ++posX;
        if (posX==charPerLine){
            posX=0;
            ++posY;
        }
        if (posY ==linePerLine){
            content += Paper.newline+Paper.newline;
            posY=0;
            ++posP;
        }
    }

    @Override
    public String getContent() {
        String ret = this.content;
        if (!(posX ==0 && posY==0)){
            int count = linePerLine - posY;
            for (int i=0;i<count;++i){
                ret+=Paper.newline;
            }
            ret+="==第"+posP+"页==";
        }
        return ret;
    }
    public void setCharPerLine(int charPerLine){
        this.charPerLine=charPerLine;
    }
    public void setLinePerLine(int linePerLine){
        this.linePerLine=linePerLine;
    }
}
